package com.jz.dao.impl;

import com.jz.dao.BaseDao;
import com.jz.dao.CourseDao;
import com.jz.entity.Course;

import java.util.List;

public class CourseDaoImpl extends BaseDao<Course> implements CourseDao {
    @Override
    public int addCourse(Course c) {
        String sql="insert into course(courseName,descs,courseType,courseImage,courseVideo,coursePrice,status,createTime)values(?,?,?,?,?,?,?,?)";
        Object[] params ={c.getCourseName(),c.getDescs(),c.getCourseType(),c.getCourseImage(),c.getCourseVideo(),c.getCoursePrice(),c.getStatus(),c.getCreateTime()};
        return update(sql,params);
    }

    @Override
    public List<Course> queryCourse(String courseName, int curPage, int pageSize) {
        StringBuffer sql=new StringBuffer("select * from course where 1=1 ");
        if(!"".equals(courseName.trim())&&courseName!=null){
            sql.append(" and courseName like '%"+courseName+"%' ");
        }
        sql.append(" limit ?,?");
        return queryMore(sql.toString(),Course.class,(curPage-1)*pageSize,pageSize);
    }

    @Override
    public int queryCourseCount(String courseName) {
        StringBuffer sql=new StringBuffer("select count(*) from course where 1=1 ");
        if(!"".equals(courseName.trim())&&courseName!=null){
            sql.append(" and courseName like '%"+courseName+"%' ");
        }
        return queryScar(sql.toString());
    }
  //查询课程拿里面的视频跟图片地址属性
    @Override
    public List<Course> queryCourse(String cids) {
        String sql="select * from course where cid in ("+cids+")";
        return queryMore(sql,Course.class);
    }

    @Override
    public int delete(String cids) {
        String sql="delete from course where cid in("+cids+")";
        return update(sql);
    }

    ;



}
